package com.yangjian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yangjian.bean.DishFlavor;
import com.yangjian.dao.DishFlavorDao;
import com.yangjian.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class DishFlavorServiceImpl  implements DishFlavorService {


    @Autowired
    private DishFlavorDao dao;

    /**
     * 根据菜单表id查询口味表
     *
     * @param DishId
     * @return
     */
    @Override
    public List<DishFlavor> findByDishId(Long DishId) {

        LambdaQueryWrapper<DishFlavor> lqw  = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,DishId);
        List<DishFlavor> dishFlavors = dao.selectList(lqw);

        return dishFlavors;
    }

    /**
     * 添加口味
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int add(DishFlavor dishFlavor) {
        int row = dao.insert(dishFlavor);
        return row;
    }

    /**
     * 根据菜品的id删除口味表数据
     *
     * @param dId
     * @return
     */
    @Override
    public int delete(long dId) {
        LambdaQueryWrapper<DishFlavor> lqw  = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,dId);
        int row = dao.delete(lqw);

        return row;
    }

}
